package com.example.aop.proxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CGLIBMethodInterceptor implements MethodInterceptor {

    private Object target;

    public CGLIBMethodInterceptor(Object target) {
        this.target = target;
    }

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        System.out.println("我是代理，开始代理");

        Object result =  method.invoke(target,args); //或者用  proxy.invoke(target,args);

        System.out.println("我是代理，结束代理");
        return result;
    }
}
